from time import sleep
from selenium import webdriver
from selenium.webdriver.support.select import Select

driver=webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(10)
driver.get("http://localhost/upload/admin/")
driver.find_element_by_css_selector('[name="username"]').send_keys("admin")
driver.find_element_by_css_selector('[type="password"]').send_keys("admin123")
driver.find_element_by_css_selector('[value="进入管理中心"]').click()
sleep(2)
frame = driver.find_element_by_css_selector('[id="menu-frame"]')
driver.switch_to.frame(frame)
sleep(2)
driver.find_element_by_css_selector('[key_data1="lis ico_1"]').click()
driver.find_element_by_link_text("添加新商品").click()
sleep(2)
driver.switch_to.default_content()

frame1=driver.find_element_by_css_selector('[id="main-frame"]')
driver.switch_to.frame(frame1)
driver.find_element_by_css_selector('[name="goods_name"]').send_keys("男士羽绒服")
select= driver.find_element_by_css_selector('[name="goods_name_style"]')
Select(select).select_by_value("strong")
sleep(2)
# Select(select).select_by_visible_text("加粗")
# Select(select).select_by_index(2)
select2=driver.find_element_by_css_selector('[name="cat_id"]')
Select(select2).select_by_index(8)
driver.find_element_by_css_selector('[name="shop_price"]').clear()
driver.find_element_by_css_selector('[name="shop_price"]').send_keys("899")

driver.find_element_by_css_selector('[name="goods_img"]').send_keys(r'C:\Users\Administrator\Desktop\b3f546fdf23a1c4a.jpg')
driver.find_element_by_css_selector('[value=" 确定 "]').click()
sleep(2)

driver.get("http://localhost/upload/")
driver.find_element_by_link_text("登录").click()
driver.find_element_by_css_selector('[name="username"]').send_keys("123456")
driver.find_element_by_css_selector('[name="password"]').send_keys("123456")
driver.find_element_by_css_selector('[name="submit"]').click()
driver.find_element_by_css_selector('[id="keyword"]').send_keys('男士羽绒服')
sleep(2)
driver.find_element_by_css_selector('[name="imageField"]').click()
driver.find_element_by_css_selector('[alt="男士羽绒服"]').click()
sleep(2)
driver.find_element_by_css_selector('[src="themes/ecmoban_meilishuo/images/goumai2.gif"]').click()
sleep(2)
driver.find_element_by_css_selector('[src="themes/ecmoban_meilishuo/images/checkout.gif"]').click()
sleep(2)
driver.find_element_by_css_selector('[type="image"]').click()


sleep(4)
driver.quit()